package com.ajk.server.service.impl;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;

import org.apache.commons.collections4.CollectionUtils;

import com.ajk.server.dao.CheckItemDictMapper;
import com.ajk.server.service.CheckItemDictService;

import com.ajk.server.model.query.CheckItemDictQuery;
import com.ajk.server.model.CheckItemDict;

/**
 * 检测项字典表  <br>
 * dict_check_item <br>
 * v1.0 2016-07-19
 */
 @Service
 public class CheckItemDictServiceImpl implements CheckItemDictService {
	
	private static final Logger logger = LoggerFactory.getLogger(CheckItemDictServiceImpl.class);
	
	@Autowired
	private CheckItemDictMapper checkItemDictMapper;
	
	/**
 	*根据ID删除 检测项字典表
 	*/
 	@Override
 	public Integer deleteCheckItemDictById(Integer id){
 		return checkItemDictMapper.deleteById(id);
 	}
 	
 	/**
 	*新增 检测项字典表
 	*/
 	@Override
 	@Transactional
 	public Integer batchInsertCheckItemDict(List<? extends CheckItemDict> checkItemDicts){
		Integer count = checkItemDictMapper.batchInsert(checkItemDicts);
		return count;
 	}
 	/**
 	*新增 检测项字典表
 	*/
 	@Override
 	@Transactional
 	public Integer insertCheckItemDict(CheckItemDict domain){
		checkItemDictMapper.insert(domain);
		Integer id = domain.getId();
		return id;
 	}

 	/**
 	*更新 检测项字典表
 	*/
 	@Override
 	@Transactional
 	public Integer updateCheckItemDict(CheckItemDict domain){
		checkItemDictMapper.update(domain);
		Integer count = domain.getId();
		return count;
 	}
 	
 	/**
 	*根据ID查询 检测项字典表
 	*/
 	public CheckItemDict findCheckItemDictById(Integer id){
 		CheckItemDict result = checkItemDictMapper.findById(id);
 		if(result!=null){
 			result.dealWith();
 		}
 		return result;
 	}

	/**
 	*通过query 查询 检测项字典表
 	*/
	public List<CheckItemDict> findCheckItemDictByQuery(CheckItemDictQuery query){
		query.dealWith();
		List<CheckItemDict> result = checkItemDictMapper.findByQuery(query);
		if(CollectionUtils.isNotEmpty(result)) {
			for (CheckItemDict checkItemDict : result) {
				checkItemDict.dealWith();
			}
		}
		return result;
	}	
	
	/**
 	*通过query count总条数
 	*/
 	public Integer countCheckItemDictByQuery(CheckItemDictQuery query){
 		query.dealWith();
 		Integer result = checkItemDictMapper.countByQuery(query);
 		return result;
 	}
 	
 	/**
 	* 通过ids查询
 	*/
 	public List<CheckItemDict> findCheckItemDictByIds(List<Integer> ids){
 		List<CheckItemDict> result = checkItemDictMapper.findByIds(ids);
		if(CollectionUtils.isNotEmpty(result)) {
			for (CheckItemDict checkItemDict : result) {
				checkItemDict.dealWith();
			}
		}
		return result;
 	}
 	
 	/**
 	*根据name查询 身体部位
 	*/
	public CheckItemDict findByName(String name){
		CheckItemDict result = checkItemDictMapper.findByName(name);
 		if(result!=null){
 			result.dealWith();
 		}
 		return result;
	}
	
	/**
 	*获取所有字典 身体部位
 	*/
	public List<CheckItemDict> findAll(){
		List<CheckItemDict> result = checkItemDictMapper.findAll();
		if(CollectionUtils.isNotEmpty(result)) {
			for (CheckItemDict checkItemDict : result) {
				checkItemDict.dealWith();
			}
		}
		return result;
	}
}	